<?php

class CommonController extends BaseController
{

    /**
     * 公共尾部文件
     */
    public function menufootAction()
    {
    }

    /**
     * 分享成功后插入一条分享成功数据
     */
    public function addShareLogAction(){
        $reqs = file_get_contents("php://input");
        @parse_str($reqs, $reqs);
        $share_goals = $reqs['share_goals']??'';
        $title = $reqs['title']??'';
        $link = $reqs['link']??'';
        $req = array('user_id' => $this->user_id);
        $postData = array(
            'share_goals'=>$share_goals,
            'title'=>$title,
            'desc'=>'#紫燕燃动世界杯#',
            'link'=>$link,
            'imgUrl'=>'/img/alert/share_fen.jpg'
        );
        $post = array('payload' => base64_encode(http_build_query($postData)));
        $rest = new \Base\Rest();
        $res = $rest->Post('SharingLog', $req, $post);
        $tem['success'] = $res->isSuccess();
        $tem['response'] = $res->getResponse();
        \Util\LogUtil::log('share','res:'.json_encode($tem,true));
        if ($res->isSuccess()) {
            $re = $res->getResponse();
            Response::Success($re['share_num']);
        } else {
            Response::Error(201, $res->getErrorMessage());
        }

    }

    /**
     * 获取省市区地址三级联动
     */
    public function regionSelectAction()
    {
        $region_biz = new \Biz\Region();
        // 中国的ID是1
        // 省
        $province_list = $region_biz->getRegionListByParentId(1);
        // 市
        if (property_exists($this->view, 'province_id')) {
            $province_id = $this->view->province_id;
        } else {
            $province_info = reset($province_list);
            $province_id = $province_info['id'];
        }
        $city_list = $region_biz->getRegionListByParentId($province_id);
        // 区域
        if (property_exists($this->view, 'city_id')) {
            $city_id = $this->view->city_id;
        } else {
            $city_info = reset($city_list);
            $city_id = $city_info['id'];
        }
        $area_list = $region_biz->getRegionListByParentId($city_id);
        $this->view->province_list = $province_list;
        $this->view->city_list = $city_list;
        $this->view->area_list = $area_list;
    }
}
